﻿

@using Single_SignOn.ResX
@model Single_SignOn.Areas.Web.Models.ApplicationListModels

@{
    ViewBag.Title = @ResourceTools.GetResource("Resource", "ApplicationList");
    Layout = "~/Areas/Web/Views/Shared/_LayoutHeader.cshtml";
}
    @using (Html.BeginForm()) {
        <div>
            <div id="contentApplicationList">     
                    <div class="error-summary"></div>  
                    <div class="clear"></div>    
                <div style="width: 100%;" class="center">
                    <table style="width: 100%;" class="center">
                        <tr style="width: 100%;" class="center">
                            <td style="width: 100%;" class="center">
                                @Html.Partial("_Company", Model.Companies)
                            </td>

                        </tr>
                        <tr style="width: 100%;" class="center">
                            <td style="width: 100%;" class="center">
                                @Html.Partial("_Language", Model.Languages)
                            </td>
                        </tr>
                        <tr style="width: 100%;" class="center">
                            <td style="width: 100%;" class="center">
                                @{
                                        if (Model.ApplicationLists != null)
                                        {@Html.Partial("_ApplicationList", Model.ApplicationLists)}
                                }
                            </td>
                        </tr>
                    </table>
                </div>
            </div>          
        </div>
    }

    <!-- Json passer -->
    <div class="display">
        <script type="text/javascript">

            $(document).ready(function () {

                $('#login').click(function () {

                    var oKeyDataObj = {
                        "RadioLogin": "" + $('input[name=radioLogin]:checked').val() + ""
                    };

                    $.ajax({
                        url: '@Url.Action("Login", "Authentication")',
                        type: "POST",
                        dataType: "json",
                        contentType: "application/json; charset=utf-8",
                        data: JSON.stringify(oKeyDataObj),
                        success: function (data, textStatus, xhr) {
                            //At this point I would like to redirect
                            window.location.href = data.redirectToUrl;
                        },
                        error: function (xhr, textStatus, errorThrown) {
                            $(".error-summary").html(xhr.responseText);
                        }
                    });

                    return false;
                });


            });

        </script>
    </div>
    <!-- Json passer -->